package oo

import (
	"errors"
	"strings"
)

type SubstringV5 struct {
	String
}

func (o *SubstringV5) Ints() ([]int, error) {
	ss := o.split()

	var number Number
	for _, s := range ss {
		if !number.IsInt(s) {
			return nil, errors.New(s + " is not an integer")
		}
	}

	return o.mapper(ss, number.ToInt), nil
}

func (o *SubstringV5) split() []string {
	return strings.Split(o.value, ",")
}

func (o *SubstringV5) mapper(ss []string, fn func(s string) int) []int {
	var values []int
	for _, s := range ss {
		values = append(values, fn(s))
	}
	return values
}
